<!DOCTYPE html>
<html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-0 vector-toc-not-available vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-0 skin-theme-clientpref-day vector-sticky-header-enabled" lang="de" dir="ltr"><head>
<meta charset="UTF-8">
<title>Attribut (Programmierung)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" href="./_res_/favicon.png">
<link rel="canonical" href="https://de.wikipedia.org/wiki/Attribut_(Programmierung)"> <link href="./_mw_/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./_mw_/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./_mw_/ext.wikimediamessages.styles.css" rel="stylesheet" type="text/css">
<link href="./_mw_/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./_mw_/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./_mw_/skins.vector.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link href="./_mw_/ext.gadget.citeRef.css" rel="stylesheet" type="text/css">
<link href="./_mw_/ext.gadget.defaultPlainlinks.css" rel="stylesheet" type="text/css">
<link href="./_mw_/ext.gadget.dewikiCommonHide.css" rel="stylesheet" type="text/css">
<link href="./_mw_/ext.gadget.dewikiCommonLayout.css" rel="stylesheet" type="text/css">
<link href="./_mw_/ext.gadget.dewikiCommonStyle.css" rel="stylesheet" type="text/css">
<link href="./_mw_/ext.gadget.dewikiDarkmode.css" rel="stylesheet" type="text/css">
<link href="./_mw_/ext.gadget.dewikiResponsive.css" rel="stylesheet" type="text/css">
<link href="./_mw_/ext.gadget.specialSearch.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="./_mw_/site.styles.css">
<link rel="stylesheet" type="text/css" href="./_mw_/noscript.css">
<link rel="stylesheet" type="text/css" href="./_res_/footer.css">
<link rel="stylesheet" type="text/css" href="./_res_/vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Attribut_Programmierung rootpage-Attribut_Programmierung skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading"><span class="mw-page-title-main">Attribut (Programmierung)</span></h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="contentSub">
<div id="mw-content-subtitle"></div>
</div>
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="de" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="de" dir="ltr"><p>Ein <b>Attribut</b> (von <span style="font-style:normal;font-weight:normal"><a href="Latein" title="Latein">lateinisch</a></span> <span lang="la-Latn" style="font-style:italic"><i>attribuere</i></span> ‚zuteilen‘, ‚zuordnen‘), auch <a href="Eigenschaft" title="Eigenschaft">Eigenschaft</a> genannt, gilt im Allgemeinen als <a href="Merkmal" title="Merkmal">Merkmal</a>, Kennzeichen, Informationsdetail etc., das einem konkreten <a href="Objekt_(Programmierung)" title="Objekt (Programmierung)">Objekt</a> zugeordnet ist. Dabei wird unterschieden zwischen der <a href="Bedeutung" title="Bedeutung">Bedeutung</a> (z. B. Augenfarbe) und der konkreten Ausprägung (z. B. blau) des Attributs.
</p><p>In der <a href="Informatik" title="Informatik">Informatik</a> wird unter Attribut die Definitionsebene für diese Merkmale verstanden. Als solche werden sie analytisch ermittelt, definiert und beschrieben sowie für einen bestimmten <a href="Objekttyp" class="mw-redirect" title="Objekttyp">Objekttyp</a> als Elemente seiner Struktur festgelegt („<a href="Datenmodellierung" title="Datenmodellierung">modelliert</a>“). <a href="Daten" title="Daten">Daten</a> über die Objekte werden in dieser Struktur und nur mit ihrem Inhalt, den Attributwerten, gespeichert. Jedes Objekt repräsentiert sich somit durch die Gesamtheit seiner Attributwerte.
</p><p>Jedem Attribut sind Regeln zugeordnet, die als <a href="Operation_(Informatik)" title="Operation (Informatik)">Operationen</a> bezeichnet werden. Daraus folgt, dass eine Objektdefinition durch die Definition von <a href="Datentyp" title="Datentyp">Datentypen</a> erweitert werden kann. Ein Darstellungsformat, ein Standardwert sowie gültige Operationen und Einschränkungen (z. B. ist <a href="Division_durch_null" class="mw-redirect" title="Division durch null">Division durch null</a> nicht erlaubt) können an der Definition von Attributen beteiligt sein oder umgekehrt als Attribut des <a href="Objekttyp" class="mw-redirect" title="Objekttyp">Objekttyps</a> bezeichnet werden.
</p><p>In der <a href="Computergrafik" title="Computergrafik">Computergrafik</a> zum Beispiel können Linienobjekte beispielsweise Attribute wie Anfangspunkt und Endpunkt (mit <a href="Koordinatensystem" title="Koordinatensystem">Koordinaten</a> als Werten), Breite (mit einer <a href="Gleitkommazahl" title="Gleitkommazahl">Gleitkommazahl</a> als Wert), Farbe (mit beschreibenden Werten wie Rot, Gelb, Grün oder Blau oder in einem bestimmten Farbmodell definierte Werte wie im <a href="RGB-Farbraum" title="RGB-Farbraum">RGB-Farbraum</a>) usw. aufweisen und Kreisobjekte können zusätzlich mit den Attributen <a href="Mittelpunkt" title="Mittelpunkt">Mittelpunkt</a> und <a href="Radius" title="Radius">Radius</a> definiert werden.
</p><p>In <a href="Landinformationssystem" title="Landinformationssystem">Land-</a> bzw. <a href="Geoinformationssystem" title="Geoinformationssystem">Geoinformationssystemen</a> (GIS) ist die Datengrundlage von Objekten ihre Lage in einem horizontalen Koordinatensystem (meist ebene <a href="Gau%C3%9F-Kr%C3%BCger-Koordinaten" class="mw-redirect" title="Gauß-Krüger-Koordinaten">Gauß-Krüger-Koordinaten</a> oder <a href="Geografische_Breite" class="mw-redirect" title="Geografische Breite">geografische Breite</a> plus <a href="Geografische_L%C3%A4nge" class="mw-redirect" title="Geografische Länge">Länge</a>). Alle weiteren Eigenschaften des Objekts (z. B. Höhe, Größe, Zweck, Zeitpunkt der Erfassung) werden den Lagekoordinaten als Attribut zugeordnet. Hingegen wird die <a href="Meeresh%C3%B6he" class="mw-redirect" title="Meereshöhe">Meereshöhe</a> meist in ein <a href="Zweidimensional" class="mw-redirect" title="Zweidimensional">zweidimensionales</a> Modell (2½-D) realisiert, also als Objekt mit größerer Bedeutung; bei <a href="3D" title="3D">3D</a>-Modellen ist sie hingegen den Lagekorrdinaten gleichwertig.
Objektattribute sind im Regelfall mit anderen Daten des GIS <a href="Verkn%C3%BCpfung_(Computer)" title="Verknüpfung (Computer)">verknüpfbar</a>, heute meist auch mit anderen, verwandten <a href="Datenbank" title="Datenbank">Datenbanken</a>.
</p>
<div class="mw-heading mw-heading2"><h2 id="Verarbeitung">Verarbeitung</h2></div>
<p>Zur Verarbeitung der Daten können Attribute und Attributwerte mengen-einschränkend benutzt werden:
</p>
<ul><li>zur <a href="Selektion_(Informatik)" title="Selektion (Informatik)">Selektion</a>: Auswahl einer Objekt-Teilmenge über ihre Attributwerte; Bsp.: Geburtsdatum < 1.1.2000</li>
<li>zur <a href="Relationale_Algebra#Projektion" title="Relationale Algebra">Projektion</a>: Für die selektierten Objekte sollen nur bestimmte Attribute gelesen / verarbeitet werden; Bsp.: nur Name, Vorname, Geburtsdatum</li></ul>
<div class="mw-heading mw-heading3"><h3 id="C#"><span id="C.23"></span>C#</h3></div>
<p>In der <a href="Programmiersprache" title="Programmiersprache">Programmiersprache</a> <a href="C-Sharp" title="C-Sharp">C#</a> sind Attribute <a href="Metadaten" title="Metadaten">Metadaten</a>, die an ein Feld oder einen Codeblock wie Assemblys, öffentliche <a href="Variable_(Programmierung)" title="Variable (Programmierung)">Variablen</a> und <a href="Datentyp" title="Datentyp">Datentypen</a> angehängt sind, und entsprechen <a href="Annotation_(Java)" title="Annotation (Java)">Annotations in Java</a>. Attribute sind sowohl für den <a href="Compiler" title="Compiler">Compiler</a> als auch programmgesteuert durch <a href="Reflexion_(Programmierung)" title="Reflexion (Programmierung)">Reflexion</a> zugänglich. Mit Zugriffsmodifikator wie <i>abstract</i>, <i>sealed</i> oder <i>public</i> ist es möglich, Attribute zu erweitern.
</p><p>Ihre spezifische Verwendung als <a href="Metadaten" title="Metadaten">Metadaten</a> bleibt dem <a href="Softwareentwickler" title="Softwareentwickler">Entwickler</a> überlassen und kann eine Vielzahl von Arten von Informationen zu bestimmten Anwendungen, <a href="Klasse_(Objektorientierung)" title="Klasse (Objektorientierung)">Klassen</a> und öffentlichen <a href="Variable_(Programmierung)" title="Variable (Programmierung)">Variablen</a> abdecken, die nicht instanzspezifisch sind. Die Entscheidung, ein bestimmtes Attribut als Eigenschaft verfügbar zu machen, bleibt ebenso dem Entwickler überlassen wie die Entscheidung, sie als Teil eines größeren Anwendungsframeworks zu verwenden.
</p><p>Attribute werden als <a href="Klasse_(Objektorientierung)" title="Klasse (Objektorientierung)">Klassen</a> implementiert, die von <i>System.Attribute</i> abgeleitet sind. Sie werden häufig von den <a href="Common_Language_Runtime" title="Common Language Runtime">CLR</a>-<a href="Dienst_(Informatik)" title="Dienst (Informatik)">Diensten</a> verwendet, z. B. <a href="Component_Object_Model" title="Component Object Model">COM</a>-<a href="Interoperabilit%C3%A4t" title="Interoperabilität">Interoperabilität</a>, <a href="Remote_Procedure_Call" title="Remote Procedure Call">Remote Procedure Calls</a>, <a href="Serialisierung" title="Serialisierung">Serialisierung</a> und können zur <a href="Laufzeit_(Informatik)" title="Laufzeit (Informatik)">Laufzeit</a> abgefragt werden.
</p><p>Positionsparameter wie der erste <a href="Parameter_(Informatik)" title="Parameter (Informatik)">Parameter</a> der obigen Typzeichenfolge sind Parameter des Konstruktors des Attributs. Namensparameter wie der Boolesche Parameter im Beispiel sind eine Eigenschaft des Attributs und sollten ein konstanter Wert sein.
</p><p>Attribute sollten der <a href="XML" class="mw-redirect" title="XML">XML</a>-Dokumentation gegenübergestellt werden, die auch <a href="Metadaten" title="Metadaten">Metadaten</a> definiert, jedoch nicht in der kompilierten Assembly enthalten ist und daher nicht programmgesteuert aufgerufen werden kann.<sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="Beispiele">Beispiele</h2></div>
<p>Das folgende Beispiel in der <a href="Programmiersprache" title="Programmiersprache">Programmiersprache</a> <a href="C-Sharp" title="C-Sharp">C#</a> zeigt die <a href="Klasse_(Objektorientierung)" title="Klasse (Objektorientierung)">Klassen</a> <code>Partei</code>, <code>Abgeordneter</code> und <code>Parlament</code>, die öffentliche Attribute deklarieren. Die meisten dieser Attribute können von anderen <a href="Objekt_(Programmierung)" title="Objekt (Programmierung)">Objekten</a> gelesen, aber nicht geändert werden, weil die <code>set</code>-<a href="Methode_(Programmierung)" title="Methode (Programmierung)">Methode</a> mit dem <a href="Zugriffsmodifikator" title="Zugriffsmodifikator">Zugriffsmodifikator</a> <code>private</code> <a href="Deklaration_(Programmierung)" title="Deklaration (Programmierung)">deklariert</a> ist. Das Attribut <code>mitgliedsbeitrag</code> der Klasse <code>Partei</code> und das Attribut <code>maximalGroesse</code> der Klasse <code>Parlament</code> können auch von anderen Objekten geändert werden.
</p><p>
Die <a href="Datentyp" title="Datentyp">Datentypen</a> von Attributen können <a href="Datentyp#Elementare_Datentypen" title="Datentyp">elementare Datentypen</a> oder <a href="Klasse_(Objektorientierung)" title="Klasse (Objektorientierung)">Klassen</a>, also Objekttypen sein. Die meisten Attribute im Beispiel haben elementare Datentypen. Das Attribut <code>vorsitzender</code> der Klasse <code>Abgeordneter</code> hat den Objekttyp <code>Abgeordneter</code>. Das Attribut <code>mitglieder</code> der Klasse <code>Partei</code> hat den <a href="Generischer_Typ" title="Generischer Typ">generischen Typ</a> <code>List<Person></code>, ist also eine Liste mit dem Typparameter <code>Person</code>.</p><div class="mw-highlight mw-highlight-lang-c# mw-content-ltr" dir="ltr"><pre><span></span><span class="k">class</span><span class="w"> </span><span class="nc">Person</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="kt">string</span><span class="w"> </span><span class="n">vorname</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="k">private</span><span class="w"> </span><span class="k">set</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="kt">string</span><span class="w"> </span><span class="n">nachname</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="k">private</span><span class="w"> </span><span class="k">set</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="n">Date</span><span class="w"> </span><span class="n">geburtsdatum</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="k">private</span><span class="w"> </span><span class="k">set</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="n">List</span><span class="o"><</span><span class="kt">string</span><span class="o">></span><span class="w"> </span><span class="n">nationalitäten</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="k">private</span><span class="w"> </span><span class="k">set</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="kt">string</span><span class="w"> </span><span class="n">MailAdresse</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="k">private</span><span class="w"> </span><span class="k">set</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="kt">string</span><span class="w"> </span><span class="n">Postanschrift</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="k">private</span><span class="w"> </span><span class="k">set</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>
<span class="p">}</span>
<span class="k">class</span><span class="w"> </span><span class="nc">Partei</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="n">List</span><span class="o"><</span><span class="n">Person</span><span class="o">></span><span class="w"> </span><span class="n">mitglieder</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="k">private</span><span class="w"> </span><span class="k">set</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="kt">double</span><span class="w"> </span><span class="n">mitgliedsbeitrag</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="k">set</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>
<span class="p">}</span>
<span class="k">class</span><span class="w"> </span><span class="nc">Abgeordneter</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">Person</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="n">Partei</span><span class="w"> </span><span class="n">partei</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="k">private</span><span class="w"> </span><span class="k">set</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>
<span class="p">}</span>
<span class="k">class</span><span class="w"> </span><span class="nc">Parlament</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="n">List</span><span class="o"><</span><span class="n">Abgeordneter</span><span class="o">></span><span class="w"> </span><span class="n">abgeordnete</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="k">private</span><span class="w"> </span><span class="k">set</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="n">Abgeordneter</span><span class="w"> </span><span class="n">vorsitzender</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="k">private</span><span class="w"> </span><span class="k">set</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">maximalGroesse</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="k">set</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>
<span class="p">}</span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="Siehe_auch">Siehe auch</h2></div>
<ul><li><a href="Attribut_(UML)" title="Attribut (UML)">Attribut (UML)</a></li></ul>
<div class="mw-heading mw-heading2"><h2 id="Einzelnachweise">Einzelnachweise</h2></div>
<ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><a href="#cite_ref-1">↑</a></span> <span class="reference-text">Hanspeter Mössenböck, University of Linz: <a rel="nofollow" class="external text" href="https://ssw.jku.at/Teaching/Lectures/CSharp/Tutorial/">C# Tutorial</a></span>
</li>
</ol></div><!--htdig_noindex--><div><div class="zim-footer">
Dieser Artikel wurde von <a class="external text" title="Zuletzt bearbeitet am 2022-10-28" href="https://de.wikipedia.org/wiki/?title=Attribut_(Programmierung)&oldid=227437557">Wikipedia</a> herausgegeben. Der Text ist unter <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.de">Creative Commons Attribution-Share Alike 4.0</a> verfügbar, sofern nicht anders angegeben. Für die Mediendateien können zusätzliche Bedingungen gelten.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>
<script src="./_webp_/webpHandler.js"></script>
</body></html>